import { StatueUserPlayer } from "../../../scene/player/entity/StatueUserPlayer";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { LGXBDirection } from "../dir/LGXBDirection";
import { DirectionType } from "../../../scene/modle/data/DirectionType";
import { AStarPoint } from "../../../scene/map/AStarPoint";
import { LGXBMap } from "../map/LGXBMap";
import { MovePlayer } from "../../../scene/player/entity/MovePlayer";
import { ShadowListManager } from "./ShadowListManager";
import { Cache } from "../../../cache/Cache";
import { EDressPos } from "../../../../../Message/Public/EDressPos";
import { RolePlayer } from "../../../scene/player/entity/RolePlayer";
import { EEntityAttribute } from "../../../../../Message/Public/EEntityAttribute";
import { ActionType } from "../../../scene/modle/data/ActionType";
import { DataEvent } from "../../../events/DataEvent";
type int = number;
//class RolePlayerCopy
    
    export  class RolePlayerCopy extends StatueUserPlayer
    {
        constructor()
        {
            super();
            this.directionMap = new Map<any, any> /* flash.utils.Dictionary */(false);
            _isDead = false;
            _speed.interval = 90;
            _speed.timeSpeed = 90;
            this.directionArrowBox = new Object /* flash.display.Sprite */();
            this.addChildAt(this.directionArrowBox, 0);
            this.effectSWFPlayer = ObjectPool.getObject(SWFPlayer);
            this.effectSWFPlayer.timeRate = 5;
            this.effectSWFPlayer.loadComplete = this.onLoadCompleted;
            this.effectSWFPlayer.load("LGXB_personEffect.swf", ModelType.NormalSwf, null);
            this.addChild(this.effectSWFPlayer);
            this.directionMap[LGXBDirection.toDown] = DirectionType.South;
            this.directionMap[LGXBDirection.toTop] = DirectionType.North;
            this.directionMap[LGXBDirection.toLeft] = DirectionType.West;
            this.directionMap[LGXBDirection.toRight] = DirectionType.East;
            this.jumpAnimate = false;
            return;
        }

        /* internal  */setingNextPointAndDir(): void
        {
            var loc1=_pathArray.shift();
            _nextPoint = new AStarPoint(loc1.x, loc1.y);
            this.curToDirect = LGXBDirection.instance.getDirectPointByTwoPoint(_currentPoint, _nextPoint);
            return;
        }

        protected /* override */ nextPathPoint(arg1: Boolean=false): void
        {
            var loc1=null;
            if (this.hasNextPoint()) 
            {
                loc1 = LGXBMap.instance.changeTileToPixelPoint(_nextPoint);
                _speed.setPoint(this.x, this.y, loc1.x, loc1.y);
                this.direction = _speed.direction;
                if (arg1) 
                {
                    walkStart(_nextPoint);
                }
                else 
                {
                    walkGridStart(_nextPoint);
                }
            }
            else 
            {
                this.walkEnd();
            }
            return;
        }

        protected /* override */ walkGridEnd(): void
        {
            if (_nextPoint) 
            {
                _currentPoint.x = _nextPoint.x;
                _currentPoint.y = _nextPoint.y;
                _currentPoint.value = _nextPoint.value;
            }
            else 
            {
                _currentPoint = LGXBMap.instance.changePixelToTilePoint(new Object /* flash.geom.Point */(this.x, this.y));
            }
            if (typeof pointChangeHandler === "function") 
            {
                pointChangeHandler();
            }
            return;
        }

        public /* override */ walking(arg1: Array<any>): void
        {
            throw new Error("不允许调用");
        }

        public /* override */ follow(arg1: MovePlayer): void
        {
            throw new Error("不允许调用");
        }

        protected /* override */ isInSafeArea(): Boolean
        {
            throw new Error("不允许调用");
        }

        public /* override */ setTitlePoint(arg1: int, arg2: int, arg3: Boolean=true): void
        {
            throw new Error("不允许调用");
        }

        public set jumpAnimate(arg1: Boolean)
        {
            this._jumpAnimate = arg1;
            if (_isMove || !this.hasFinishSteps) 
            {
                this.jumpAnimateHander();
            }
            return;
        }

        /* internal  */jumpAnimateHander(): void
        {
            var loc1=null;
            var loc3=null;
            ShadowListManager.instance.addEffect(_currentPoint, pathArray, this);
            if (_pathArray.length > 1) 
            {
                loc3 = _pathArray[_pathArray.length - 2];
                loc1 = new AStarPoint(loc3.x, loc3.y);
            }
            else 
            {
                loc1 = _currentPoint;
            }
            var loc2=_pathArray[(_pathArray.length - 1)];
            if (loc2) 
            {
                _currentPoint = new AStarPoint(loc2.x, loc2.y);
                this.curToDirect = LGXBDirection.instance.getDirectPointByTwoPoint(loc1, _currentPoint);
                this.setPosition(_currentPoint.x, _currentPoint.y, false, this.curToDirect);
            }
            _pathArray.length = 0;
            this.stopMove();
            return;
        }

        public get curToDirect(): int
        {
            return this._curToDirect;
        }

        public set curToDirect(arg1: int)
        {
            this._curToDirect = arg1;
            return;
        }

        /* internal  */onLoadCompleted(arg1: SWFPlayer): void
        {
            if (arg1.movieClipData) 
            {
                arg1.movieClipData.isClear(false);
            }
            return;
        }

        public checkIsAtThreeRoad(): Boolean
        {
            return LGXBMap.instance.isThreeRoads(_currentPoint.x, _currentPoint.y);
        }

        public updateEquitment(): void
        {
            var loc8=0;
            var loc10=0;
            var loc1=Cache.instance.role;
            var loc2=loc1.careerEnabled;
            var loc3=Cache.instance.pack.rolePackCache.getAllItemsByCareer(loc2);
            var loc4=loc3[(EDressPos._EDressPosWeapon - 1)];
            var loc5=loc1.entityInfo.sex;
            var loc6=RolePlayer.instance.camp;
            var loc7;
            delete (loc7 = loc1.getWeaponsDicByCareer(loc2))[EEntityAttribute._EAttributeWing];
            var loc9=RolePlayer.instance.entityInfo.entityInfo.wuxingType;
            if (loc4 != null) 
            {
                loc8 = RolePlayer.instance.reserveJs.weaponStPerLv;
            }
            var loc11;
            if ((loc11 = loc3[(EDressPos._EDressPosWing - 1)]) != null) 
            {
                loc10 = RolePlayer.instance.reserveJs.wingStrPerLv;
            }
            this.updateUserModel(loc6, loc5, loc2, loc7, loc8, loc10, loc9);
            return;
        }

        public updateUserModel(arg1: int, arg2: int, arg3: int, arg4: Map<any, any> /* flash.utils.Dictionary */, arg5: int=0, arg6: int=0, arg7: int=0): void
        {
            this.equipsDictionary = arg4;
            this.camp = arg1;
            this.sex = arg2;
            this.career = arg3;
            this.reserveJs.weaponStPerLv = arg5;
            this.reserveJs.wingStrPerLv = arg6;
            this.updateEquipByDic(arg4);
            this.wxPlayerShow();
            return;
        }

        public showArrow(arg1: int): void
        {
            var loc1=null;
            if (this.directionArrowBox.numChildren == 1) 
            {
                this.directionArrowBox.removeChildAt(0);
            }
            loc1 = LGXBDirection.instance.getDirectionArrowByFlag(arg1);
            var loc2=30;
            var loc3=arg1;
            switch (loc3) 
            {
                case LGXBDirection.toLeft:
                {
                    loc1.x = -loc2 - loc1.width;
                    loc1.y = -int(loc1.height / 2);
                    loc1.alpha = 1;
                    break;
                }
                case LGXBDirection.toRight:
                {
                    loc1.x = loc2;
                    loc1.y = -int(loc1.height / 2);
                    loc1.alpha = 1;
                    break;
                }
                case LGXBDirection.toTop:
                {
                    loc1.x = -int(loc1.width / 2);
                    loc1.y = -loc2 - loc1.height;
                    loc1.alpha = 0.8;
                    break;
                }
                case LGXBDirection.toDown:
                {
                    loc1.x = -int(loc1.width / 2);
                    loc1.y = loc2;
                    loc1.alpha = 1;
                    break;
                }
            }
            this.directionArrowBox.addChild(loc1);
            this.directionArrowBox.visible = true;
            return;
        }

        public /* override */ removeToStage(arg1: Object /* flash.display.DisplayObjectContainer */=null, arg2: Boolean=false): Boolean
        {
            if (this.effectSWFPlayer) 
            {
                this.effectSWFPlayer.stop();
            }
            _timer.stop();
            return true;
        }

        public /* override */ addToStage(arg1: Object /* flash.display.DisplayObjectContainer */): Boolean
        {
            if (this.effectSWFPlayer) 
            {
                this.effectSWFPlayer.play();
            }
            _timer.start();
            return true;
        }

        public hideArrow(): void
        {
            this.directionArrowBox.visible = false;
            return;
        }

        public continueMoveToSide(arg1: int): void
        {
            this.startMove();
            this.nextPathPoint(true);
            return;
        }

        protected /* override */ onMove(): void
        {
            this.x = int(this.x + _speed.xSpeed);
            this.y = int(this.y + _speed.ySpeed);
            return;
        }

        public setPosition(arg1: int, arg2: int, arg3: Boolean, arg4: int): void
        {
            var loc1=null;
            _nextPoint = null;
            if (arg3) 
            {
                _currentPoint = LGXBMap.instance.changePixelToTilePoint(new Object /* flash.geom.Point */(arg1, arg2));
                loc1 = LGXBMap.instance.changeTileToPixelPoint(_currentPoint);
                this.x = loc1.x;
                this.y = loc1.y;
            }
            else 
            {
                _currentPoint.x = arg1;
                _currentPoint.y = arg2;
                loc1 = LGXBMap.instance.changeTileToPixelPoint(_currentPoint);
            }
            this.x = loc1.x;
            this.y = loc1.y;
            this.curToDirect = arg4;
            this.setPlayerStandDirect();
            return;
        }

        public gotoPath(arg1: Array<any>): void
        {
            if (isMove || !(_pathArray.length == 0)) 
            {
                return;
            }
            _pathArray = arg1 != null ? arg1 : [];
            if (this._jumpAnimate) 
            {
                this.jumpAnimateHander();
            }
            else 
            {
                this.startMove();
                this.nextPathPoint(true);
            }
            return;
        }

        protected /* override */ walkEnd(): void
        {
            if (_nextPoint) 
            {
                _currentPoint.x = _nextPoint.x;
                _currentPoint.y = _nextPoint.y;
                _currentPoint.value = _nextPoint.value;
                targetTilePoint.x = _nextPoint.x;
                targetTilePoint.y = _nextPoint.y;
                targetTilePoint.value = _nextPoint.value;
            }
            else 
            {
                _currentPoint = LGXBMap.instance.changePixelToTilePoint(new Object /* flash.geom.Point */(this.x, this.y));
                targetTilePoint.x = _currentPoint.x;
                targetTilePoint.y = _currentPoint.y;
            }
            this.stopMove();
            return;
        }

        public /* override */ stopWalking(): void
        {
            _nextPoint = null;
            _currentPoint = LGXBMap.instance.changePixelToTilePoint(new Object /* flash.geom.Point */(this.x, this.y));
            targetTilePoint.x = _currentPoint.x;
            targetTilePoint.y = _currentPoint.y;
            if (_isMove == false && _nextPointAry.length > 0) 
            {
                _isMove = true;
                this.nextPathPoint();
            }
            return;
        }

        protected /* override */ startMove(): void
        {
            super.startMove();
            this.hideArrow();
            this.effectSWFPlayer.stop();
            this.effectSWFPlayer.visible = false;
            return;
        }

        public /* override */ stopMove(): void
        {
            _isMove = false;
            this.actionState = ActionType.Stand;
            _nextPoint = null;
            this.setPlayerStandDirect();
            this.effectSWFPlayer.play();
            this.effectSWFPlayer.visible = true;
            this.dispatchEvent(new Object /* flash.events.Event */("#stopMove#"));
            return;
        }

        /* internal  */setPlayerStandDirect(): void
        {
            var loc2=0;
            if (this.curToDirect == LGXBDirection.toNone) 
            {
                return;
            }
            var loc1=this.checkIsAtThreeRoad();
            if (loc1) 
            {
                this.hideArrow();
            }
            else 
            {
                loc2 = LGXBMap.instance.autoFindNextRoadPointDirect(this.curToDirect, currentPoint.x, currentPoint.y);
                this.direction = this.directionMap[loc2];
                this.showArrow(loc2);
            }
            return;
        }

        public get hasFinishSteps(): Boolean
        {
            return _pathArray.length == 0;
        }

        protected /* override */ hasNextPoint(): Boolean
        {
            var loc1=false;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            if (this.hasFinishSteps || !_isMove) 
            {
                return false;
            }
            if (this._pointToSide == LGXBDirection.toNone) 
            {
                loc1 = this.checkIsAtThreeRoad();
                if (loc1) 
                {
                    loc2 = LGXBMap.instance.getThreeRoadPoints(this.curToDirect, _currentPoint.x, _currentPoint.y);
                    loc3 = _pathArray[0];
                    loc4 = new AStarPoint(loc3.x, loc3.y);
                    this._pointToSide = LGXBDirection.instance.getDirectPointByTwoPoint(_currentPoint, loc4);
                    this.dispatchEvent(new DataEvent("#toCheckSide#", [loc2, this._pointToSide]));
                    return false;
                }
                this.setingNextPointAndDir();
            }
            else 
            {
                this._pointToSide = LGXBDirection.toNone;
                this.setingNextPointAndDir();
            }
            return true;
        }

        /* internal */ /* var */_curToDirect: int=-1;

        /* internal */ /* var */directionArrowBox: Object /* flash.display.Sprite */;

        /* internal */ /* var */effectSWFPlayer: SWFPlayer;

        /* internal */ /* var */directionMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_pointToSide: int=-1;

        /* internal */ /* var */_jumpAnimate: Boolean=false;

        public /* var */equipsDictionary: Map<any, any> /* flash.utils.Dictionary */;
    }
